import axios from 'axios'

const instance = axios.create({
  baseURL: 'http://localhost:8181',
  timeout: 5000
})

// 请求拦截器（如果有token可加）
instance.interceptors.request.use(config => {
  const token = localStorage.getItem('token')
  if (token) {
    config.headers.Authorization = `Bearer ${token}`
  }
  return config
}, error => Promise.reject(error))

// 响应拦截器
instance.interceptors.response.use(response => response.data, error => Promise.reject(error.response?.data || error))

export const moveoutApi = {
  // 分页列表接口
  getList(page, size) {
    return instance.get(`/moveout/list/${page}/${size}`)
  },
  // 搜索接口，params 包含 key, value, page, size
  search(params) {
    return instance.get('/moveout/search', { params })
  },
  // 迁出操作
  moveout(id, reason) {
    return instance.put(`/moveout/moveout/${id}/${reason}`)
  }
}
